
package com.eyedog.video.widgets;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.eyedog.library.utils.DensityUtils;
import com.eyedog.uilibrary.widgets.RoundViewOutlineProvider;

@SuppressLint("AppCompatCustomView")
public class AdvImageView extends ImageView {
    float ratio = 3.86f;

    public AdvImageView(Context context) {
        this(context, null);
    }

    public AdvImageView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public AdvImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public AdvImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
        int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        setOutlineProvider(new RoundViewOutlineProvider(DensityUtils.dp2px(context, 10)));
        setClipToOutline(true);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = MeasureSpec.getSize(heightMeasureSpec);
        int scaledHeight = (int) (width / ratio);
        super.onMeasure(widthMeasureSpec,
            MeasureSpec.makeMeasureSpec(scaledHeight, MeasureSpec.EXACTLY));
    }
}
